using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using MimeCloud.AssetManagement.Silverlight.DataServiceConsumer.AssetManagerDataServiceReference;


namespace MimeCloud.AssetManagement.AssetRendering
{
    public class ThumbnailHelper
    {
        public static BitmapImage GetImageForContent(AssetContent content)
        {
            if (content.RepositoryList[0] is NonStoredRepositoryBase)
            {
                //get image from local source
                if (content.AssetContentRepositoryList[0] is LocalFileStoreSingleAssetRepository)
                {
                    return new BitmapImage(new Uri(content.AssetContentRepositoryList[0].URLPrefix));
                }
                else if (content.AssetContentRepositoryList[0] is MemorySingleAssetRepository)
                {
                    byte[] sourceFile =
                        (content.AssetContentRepositoryList[0] as MemorySingleAssetRepository).AssetContent as byte[];
                    return Reading.ReadImageFromData(sourceFile);
                }
                else return null;
            }
            else
                return new BitmapImage(new Uri(ContentHelper.GetUrlOfContent(content)));
        }

        public static String GetDisplayPathForContent(IAssetContent content)
        {
            if (content.AssetContentRepositoryList[0] is NonStoredRepositoryBase)
            {
                //get image from local source
                if (content.AssetContentRepositoryList[0] is LocalFileStoreSingleAssetRepository)
                {
                    return content.AssetContentRepositoryList[0].URLPrefix;
                }
                else if (content.AssetContentRepositoryList[0] is MemorySingleAssetRepository)
                {
                    return Web.WebPath.WebPathCombine(content.AssetContentRepositoryList[0].URLPrefix, content.AssetPath);
                }
                else return String.Empty;
            }
            else
                return Web.WebPath.WebPathCombine(content.AssetContentRepositoryList[0].URLPrefix, content.AssetPath);
        }
    }
}
